
// pages/shop/product.js
var app = getApp();
var currentShopId;
var WxParse = require('../../wxParse/wxParse.js');
Page({
  data:{},
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    var shop = wx.getStorageSync('shop');
    currentShopId = shop.id;
    app.func.req('products/show', {
      shop_id: currentShopId,
      id: options.id,
      is_business: 1
      },'GET',function(res){
        if (res.result.status == 0) {
          wx.showToast({
            title: '该商品未上架',
            image: '/images/fail.png',
            duration: 2000
          });
        }
        that.setData({
          product: res.result
        })
        WxParse.wxParse('content', 'html', res.result.content, that, 0);
      }, {
        'token': wx.getStorageSync('token')
      })
  },
  onShareAppMessage: function () {
    return {
      title: '你的朋友分享了' + this.data.product.name,
      imageUrl: this.data.product.logo.replace(/(^\s*)|(\s*$)/g, ""),
      path: 'pages/share/share?product_id=' + this.data.product.id + '&shop_id=' + currentShopId + '&product_share=true'
    }
  },
  articleLink: function(){
    var that = this;
    var url = 'pages/share/share?product_id=' + this.data.product.id + '&shop_id=' + currentShopId + '&product_share=true'
    wx.setClipboardData({
      data: url,
      success: function (res) {
        wx.showToast({
          title: '复制成功！',
          icon: 'success',
          duration: 2000,
          mask: true
        })
      }
    });
  }
})
